﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DefaultRecentDeal : System.Web.UI.Page
{
    private int CityID = 0;

    private int DealID;


    protected void Page_Load(object sender, EventArgs e)
    {
        DealID = Convert.ToInt32(Request.QueryString["dealid"]);
        if (!IsPostBack)
        {
            BindRecord(CityID, DealID);
        }
    }

    private void BindRecord(int CityID, int DealID)
    {
        var RecentDeal = new DealesDataContext();
        var query = RecentDeal.Display_RecentDeal(DealID);

        foreach (var item in query)
        {
           
            lblVendor.Text = item.VendorName.ToString();
            lblDescription.Text = item.Description.ToString();
            lblDealTitle.Text = item.Name;
            lblValue.Text = "$" + item.RegularPrice.ToString();
            lblRegularPrice.Text = "$" + item.SellPrice.ToString();
            lblDiscount.Text = item.Discount.ToString() + "%";
            lblSave.Text = "$" + (Convert.ToDouble(item.RegularPrice) - Convert.ToDouble(item.SellPrice)).ToString();
            DealImg.ImageUrl = "Admin/ImageDisplay.aspx?DealID=" + item.DealID;
            string EndDate = Convert.ToDateTime(item.SellEndDate.ToString()).ToShortDateString();
            string EndTime = Convert.ToDateTime(item.SellEndTime.ToString()).ToShortTimeString();
            DateTime starDT = Convert.ToDateTime(System.DateTime.Now);
            DateTime endDT = Convert.ToDateTime(EndDate + " " + EndTime);          
            txtFootPrint.Text = item.FootPrint.ToString();         
            var VendorDetails = new DealesDataContext();
            var Vendor = VendorDetails.Select_VendorByID(Convert.ToInt32(item.VendorID.ToString()));
            foreach (var items in Vendor)
            {
                if (items.Address1.ToString() != "")
                    lblVendor.Text += "<br/>" + items.Address1.ToString() + "<br/>";
                if (items.City.ToString() != "")
                    lblVendor.Text += items.City.ToString() + ", ";
                if (items.State.ToString() != "")
                    lblVendor.Text += items.State.ToString() + " ";
                if (items.ZipCode.ToString() != "")
                    lblVendor.Text += items.ZipCode.ToString();
                if (items.Phone_Off_.ToString() != "")
                    lblVendor.Text += "<br/>" + items.Phone_Off_.ToString();
                website.HRef = "http://" + items.Website.ToString();
            }

            var DealAddress = new DealesDataContext();
            var DealAddressList = DealAddress.Select_DealAddressByDealID(Convert.ToInt32(item.DealID.ToString()));
            RadAddressBox.DataSource = DealAddressList;
            RadAddressBox.DataBind();
            var HighLights = DealAddress.Select_HighLight(Convert.ToInt32(item.DealID.ToString()));
            foreach (var items in HighLights)
            {
                lblHighlights.Text += "<li>" + items.HighLights.ToString() + "</li>";
            }

        }


    }

    protected string TrimDescription(string Address, string City, string State, string zipcode)
    {
        string add = Address + " " + City + " " + State + " " + zipcode;
        add = add.Replace(" ", "+");
        add += "&mrt=yp";
        return add;
    }

}
